package cn.luoyifan.mq._01_hello;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

//生产者
public class Producer {
    // 队列名字
    public static final String NAME_QUEUE_HELLO_LUOYIFAN = "NAME_QUEUE_HELLO_LUOYIFAN";

    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("115.159.88.63");
//        factory.setUsername(userName);
//        factory.setPassword(password);
//        factory.setVirtualHost(virtualHost);
//        factory.setHost(hostName);
//        factory.setPort(portNumber);
        Connection connection = factory.newConnection();
        //2.创建通道
        Channel channel = connection.createChannel();
        //3.创建队列
        // 队列名、队列持久化、队列独占连接、用完删除队列、其他配置
        channel.queueDeclare(NAME_QUEUE_HELLO_LUOYIFAN,true,false,false,null);
        //4.发送消息
        channel.basicPublish("",NAME_QUEUE_HELLO_LUOYIFAN,null,"请求集合！".getBytes());
        System.out.println("消息发送完毕");

        Connection conn = factory.newConnection();
    }
}
